<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="../vue.js"></script>
  <title>todo-list</title>
</head>
<body>
  <div id="root">
    <div>
      <input 
        type="text" 
        v-model="keywords"
        v-on:keyup.enter="handleKeyup"
      >
    </div>
    <ul>
      <li
        v-for="(task,i) in tasks"
        v-if="task !== 'xxx' && task !== ''"
      >
        {{task}} <button v-on:click="handleClick(i)">X</button>
      </li>
    </ul>
  </div>
  <script>
    // MVVM
    // options
    var vm = new Vue({
      data: {
        keywords: '',
        tasks: []
      },
      el: '#root',
      methods: {
        handleKeyup() {
          this.tasks.push(this.keywords)
          this.keywords = ''
        },
        handleClick(index) {
          this.tasks.splice(index, 1)
        }
      }
    })
  </script>
</body>
</html>